﻿Imports System.Collections.ObjectModel

Public Class CertificatesGrid

    Public Sub New(src As ObservableCollection(Of CertificateItem))
        Dim lcw As New ListCollectionView(src)


        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        lcw.Filter = AddressOf Filter
        dg.ItemsSource = lcw
    End Sub


    Private Sub ButtonOldCertDetails_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        CertificatesManager.ShowCertificateDetails(DirectCast(dg.SelectedItem, CertificateItem).Certificate)
    End Sub


    Private Sub FilterChanged(sender As System.Object, e As System.Windows.RoutedEventArgs)
        DirectCast(dg.ItemsSource, ListCollectionView).Refresh()
    End Sub

    Private Function Filter(item As Object) As Boolean
        Dim ci As CertificateItem = DirectCast(item, CertificateItem)
        Return (ci.Status = SharedTools.CertificateStatus.Current AndAlso cbCurrent.IsChecked.Value) OrElse (ci.Status = SharedTools.CertificateStatus.Expired AndAlso cbExpired.IsChecked.Value) OrElse (ci.Status = SharedTools.CertificateStatus.Revoked AndAlso cbRevoked.IsChecked.Value)
    End Function

End Class
